package org.china.lanzhou.structure.convey;

import java.util.Objects;

public class Phrase {

    private long id;
    private String word;
    private Phrase guide;

    public Phrase() {
    }

    public Phrase(String word) {
        this.word = word;
    }

    public Phrase(String word, Phrase guide) {
        this.id = id;
        this.word = word;
        this.guide = guide;
    }

    public long getId() {

       if(id==0){
           long i = 0;
           for (char c : word.toCharArray()) {
               i+=c;
           }
           id= i + word.length() + System.currentTimeMillis();
       }
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }

    public Phrase getGuide() {
        return guide;
    }

    public void setGuide(Phrase guide) {
        this.guide = guide;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Phrase)) return false;
        Phrase phrase = (Phrase) o;
        return
                Objects.equals(getWord(), phrase.getWord()) ;
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId(), getWord(), getGuide());
    }

    @Override
    public String toString() {
        return "Phrase{" +
                "id=" + id +
                ", word='" + word + '\'' +
                ", guide=" + (guide==null?"":guide.getWord()) +
                '}';
    }
}
